package com.yanyu.space.common.core.bootlog;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.K;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.Ordered;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author yanyu
 */
@Slf4j
public class BootstrapLog implements CommandLineRunner, Ordered {
    @Override
    public void run(String... args) throws Exception {
        if (MapUtil.isNotEmpty(BootstrapLogContext.get())) {
            TreeMap<String, String> map =  CollectionUtil.sort(BootstrapLogContext.get(), (o1, o2) -> o1.compareTo(o2));
            for (Map.Entry<String, String> itemEntry : map.entrySet()) {
                log.info(itemEntry.getValue());
            }
        }
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }
}
